package com.scgl.prod.controller;

import java.util.Date;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.scgl.prod.domain.ScglProd;
import com.scgl.prod.service.IScglProdService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 生产计划表Controller
 *
 * @author ruoyi
 * @date 2024-10-28
 */
@RestController
@RequestMapping("/prod")
public class ScglProdController extends BaseController
{
    @Autowired
    private IScglProdService scglProdService;

    /**
     * 查询生产计划表列表
     */
    @RequiresPermissions("prod:prod:list")
    @GetMapping("/list")
    public TableDataInfo list(ScglProd scglProd)
    {
        startPage();
        List<ScglProd> list = scglProdService.selectScglProdList(scglProd);
        return getDataTable(list);
    }

    /**
     * 导出生产计划表列表
     */
    @RequiresPermissions("prod:prod:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScglProd scglProd)
    {
        List<ScglProd> list = scglProdService.selectScglProdList(scglProd);
        ExcelUtil<ScglProd> util = new ExcelUtil<ScglProd>(ScglProd.class);
        util.exportExcel(response, list, "生产计划表数据");
    }

    /**
     * 获取生产计划表详细信息
     */
    @RequiresPermissions("prod:prod:query")
    @GetMapping(value = "/{planId}")
    public AjaxResult getInfo(@PathVariable("planId") Long planId)
    {
        return success(scglProdService.selectScglProdByPlanId(planId));
    }

    /**
     * 新增生产计划表
     */
    @RequiresPermissions("prod:prod:add")
    @Log(title = "生产计划表新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScglProd scglProd)
    {
        //获取当前创建时间
        scglProd.setCreationTime(new Date());
        return toAjax(scglProdService.insertScglProd(scglProd));
    }

    /**
     * 修改生产计划表
     */
    @RequiresPermissions("prod:prod:edit")
    @Log(title = "生产计划表修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScglProd scglProd)
    {
        return toAjax(scglProdService.updateScglProd(scglProd));
    }

    /**
     * 删除生产计划表
     */
    @RequiresPermissions("prod:prod:remove")
    @Log(title = "生产计划表删除", businessType = BusinessType.DELETE)
	@DeleteMapping("/{planIds}")
    public AjaxResult remove(@PathVariable Long[] planIds)
    {
        return toAjax(scglProdService.deleteScglProdByPlanIds(planIds));
    }


}
